﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Collections;
namespace LCWMS
{
    public partial class w_so014: DockContent
    {
        public static DataTable dt_save,modify;
        private DataSet dscustomer;
        private DataSet dsmove_header;
        private DataSet dsmove_detail;
        private DataSet dsmove_con;
        private DataSet dsmove_mv;
        string str_sql_where = "";
        string move_no_str = "";
        public decimal L_qty = 0;
        public int g_str_oper = 0;
        public string str_sql_mv="";
        public string str_sql_con = "";
        string g_str_status ;
        int g_line_no = 0;
        int g_round = 0;
        string str_type = "0";
        string str_updatesql = "";

        public static string s_pop_consignor;
        public static string s_pop_sono;
        private string s_enter_flag;  //load的时候不执行enter事件 


        public void ClearCntrValue(Control parContainer, bool bol, string edit)
        {
            for (int index = 0; index < parContainer.Controls.Count; index++)
            {
                // 如果是容器类控件，递归调用自己
                if (parContainer.Controls[index].HasChildren)
                {
                    // ClearCntrValue(parContainer.Controls[index]);
                }
                else
                {
                    switch (parContainer.Controls[index].GetType().Name)
                    {

                        case "TextBox":
                            if (edit != "1")
                            {
                                parContainer.Controls[index].Text = "";
                            }
                            if (bol == false)
                                ((TextBox)parContainer.Controls[index]).ReadOnly = true;
                            else
                                ((TextBox)parContainer.Controls[index]).ReadOnly = false;
                            break;
                        case "RadioButton":
                            if (edit != "1")
                                ((RadioButton)(parContainer.Controls[index])).Checked = false;
                            ((RadioButton)(parContainer.Controls[index])).Enabled = bol;
                            break;
                        case "CheckBox":
                            if (edit != "1")
                                ((CheckBox)(parContainer.Controls[index])).Checked = false;

                            ((CheckBox)(parContainer.Controls[index])).Enabled = bol;
                            break;
                        case "ComboBox":
                            if (edit != "1")
                                //((ComboBox)(parContainer.Controls[index])).SelectedIndex = 0;
                                ((ComboBox)(parContainer.Controls[index])).Enabled = bol;
                            break;
                        case "DateTimePicker":
                            if (edit != "1")
                                ((DateTimePicker)(parContainer.Controls[index])).Text = "";
                            ((DateTimePicker)(parContainer.Controls[index])).Enabled = bol;
                            break;
                    }
                }
            }
        }
        //判断库们是否合法
        private void f_checkloc(string str_tmp1, string str_tmp2, string str_tmp3, string str_tmp4, decimal d_qty, string str_tmp5)
        {
            string str_loc = "";
            try
            {
                if (main.dbtype == "SQL")
                {
                    str_loc = main.dbservice.Sql_exec_proc_moveloc(main.g_org, str_tmp1, str_tmp2, str_tmp3, str_tmp4, d_qty, str_tmp5);
                }
                else
                {
                    str_loc = main.dbservice.oracle_exec_proc_moveloc(main.g_org, str_tmp1, str_tmp2, str_tmp3, str_tmp4, d_qty, str_tmp5);
                }

            }

            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get location  Information  !", main.g_info_dataset) + ee.ToString());
                Cursor.Current = Cursors.Default;
                return;
            }
            if (str_loc == "UNKNOWN")
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get location  Information  !", main.g_info_dataset));
                return;
            }
        }
        public w_so014()
        {

            InitializeComponent();
            dataGridView3.AutoGenerateColumns = false;
            dataGridView2.AutoGenerateColumns = false;
            dataGridView1.AutoGenerateColumns = false;
        }
        //根据条件显示补货信息与确认信息
        private void f_move_distplay()
        {
             string str_sql = "";
 
            string where1 = "";
            string where2 = "";
            where1 = " and moveout_pallet='0' and batchno='0' and  move_status='0'";
            where2 = " and moveout_pallet<>'0' and batchno<>'0'";
            move_no_str = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["replenish_no"].Value.ToString().Trim();
            str_sql_where = "consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' and move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no"].Value.ToString().Trim() + "'";
            DataRow[] tr_header = dsmove_header.Tables[0].Select(str_sql_where);

            if (tr_header.Length > 0)
            {
                show(tr_header[0]);

                dsmove_mv = new DataSet();
                dsmove_con = new DataSet();
                str_sql = "select inv_org,consignor,move_no as replenish_no,move_line_no as replenish_line_no,moveout_location as replenishout_location,moveout_pallet as replenishout_pallet,batchno,sku,sku_name," +
                          "pack_code,main_sub_flag,convert_modulus,movein_location as replenishin_location,movein_pallet as replenishin_pallet,stock_qty_m,stock_qty_s,move_qty_m as replenish_qty_m," +
                          "move_qty_s as replenish_qty_s,tmp_qty_m,tmp_qty_s,confirm_qty_m,confirm_qty_s,cubage,gross_weight,net_weight,move_cubage as replenish_cubage,move_gross_weight as replenish_gross_weight," +
                          "move_net_weight as replenish_net_weight,confirm_cubage,confirm_gross_weight,confirm_net_weight,standby_1,standby_2,standby_3,standby_4,standby_5," +
                          "standby_6,standby_7,move_status as replenish_status,confirm_dist,confirm_day,confirmer,main_dist,made_time,maker,update_time,updater,so_no,so_line_no,ext_dist,ext_batchno,   confirm_qty_m as old_confirm_qty_m,move_no,move_line_no from " + main.g_space + ".inv_move_detail where inv_org = '" + main.g_org + "' and " + str_sql_where;
                if (main.dbtype == "SQL")
                {
                    str_sql_mv = str_sql + where1;
                    dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                    str_sql_con = str_sql + where2;
                    dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);
                }
                else
                {
                    str_sql_mv = str_sql + where1;
                    dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                    str_sql_con = str_sql + where2;
                    dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                }
                dataGridView2.DataSource = dsmove_mv.Tables[0];

                dataGridView3.DataSource = dsmove_con.Tables[0];
                g_str_oper = 0;
                this.bt_Close.Enabled = true;
                this.bt_Direction.Enabled = true;
                this.bt_Confirm.Enabled = false;
                this.bt_Cancel.Enabled = false;
            }
        }
        //修改时判断库位是否可用
        private void f_modfy_loc(string str_outlocation, string str_batchno, string str_customer, string str_skus, decimal d_outqty)
        {
            DataSet ds_str1 = new DataSet();
            DataSet ds_str2 = new DataSet();
            DataSet ds_str3 = new DataSet();
            DataSet ds_str4 = new DataSet();
            DataSet ds_str5 = new DataSet();

            string str1 = "select mix_sku,mix_lotno from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and location_code='" + str_outlocation + "'";
            string str3 = "select distinct(sku) from " + main.g_space + ".inv_sku_location where inv_org = '" + main.g_org + "' and location_code='" + str_outlocation + "'";
            string str_sku = "select b.*,a.mix_lotno,a.mix_sku from " + main.g_space + ".mst_sku a left join  " + main.g_space + ".inv_sku_location b on a.inv_org = b.inv_org and a.sku=b.sku where b.inv_org = '" + main.g_org + "' and b.location_code='" + str_outlocation + "' and b.consignor='" + str_customer + "'";
                if (main.dbtype == "SQL")
                {
                    ds_str1 = main.dbservice.Sql_exec_selectsql(str1);
                    ds_str3 = main.dbservice.Sql_exec_selectsql(str3);
                    ds_str5 = main.dbservice.Sql_exec_selectsql(str_sku);
                }
                else
                {
                    ds_str1 = main.dbservice.oracle_exec_selectsql(str1);
                    ds_str3 = main.dbservice.oracle_exec_selectsql(str3);
                    ds_str5 = main.dbservice.oracle_exec_selectsql(str_sku);
                }
                if (ds_str3.Tables[0].Rows.Count > 0)//判断库位是否为空库位
                {
                    if (ds_str3.Tables[0].Rows[0]["sku"].ToString().Trim() == str_skus)//判断移入商品是否与库位上是同一种商品
                    {
                        if (ds_str1.Tables[0].Rows[0]["mix_lotno"].ToString().Trim() == "1" && ds_str5.Tables[0].Rows[0]["mix_lotno"].ToString().Trim() == "1")//是否可以混批次
                        {
                            //可以混批次
                            Judge(str_outlocation,d_outqty);
                        }
                        else
                        {
                            string str_out_batchno = "select batchno from " + main.g_space + ".inv_sku_pallet where inv_org = '" + main.g_org + "' and location_code='" + str_outlocation + "' and pallet_no =(select min(pallet_no) from " + main.g_space + ".inv_sku_pallet where  inv_org = '" + main.g_org + "' and location_code='" + str_outlocation + "')";
                            //string str_batchno = "select batchno from wms.inv_sku_pallet where location_code='" + tb_moveout_location.Text.Trim() + "' and  sku='" + cb_moveout_sku.Text.Trim() + "' and  consignor='" + cbx_h_consignor.Text.Trim() + "'";
                            //DataSet ds_batchno = new DataSet();
                            DataSet ds_out_batchno = new DataSet();
                            if (main.dbtype == "SQL")
                            {
                                //ds_batchno = main.dbservice.Sql_exec_selectsql(str_batchno);
                                ds_out_batchno = main.dbservice.Sql_exec_selectsql(str_out_batchno);
                            }
                            else
                            {
                                //ds_batchno = main.dbservice.oracle_exec_selectsql(str_batchno);
                                ds_out_batchno = main.dbservice.oracle_exec_selectsql(str_out_batchno);
                            }
                            if (str_batchno == ds_out_batchno.Tables[0].Rows[0][0].ToString().Trim())//判断是否是相同批次
                            {
                                //同一批次
                                Judge(str_outlocation, d_outqty);
                            }
                            else
                            {
                                MessageBox.Show(main.g_class.comm_getchangestring("" + str_outlocation + "The location can't deposit sku of mixed batch", main.g_info_dataset) + "!");
                                return;
                            }
                        }
                    }
                    else
                    {
                        if (ds_str1.Tables[0].Rows[0]["mix_sku"].ToString().Trim() == "1" && ds_str5.Tables[0].Rows[0]["mix_sku"].ToString().Trim() == "1")//是否可以混批次
                        {
                            //可以混商品
                            Judge(str_outlocation, d_outqty);
                        }
                        else
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("" + str_outlocation + "The location can't deposit sku of mixed batch", main.g_info_dataset) + "!");
                            return;
                        }
                    }
                }
            
            
        }
        //判断库存的库位的托盘数量
        private void Judge(string str_outloc,decimal d_outqty)
        {
            DataSet ds_str = new DataSet();
            string str = "";
            str = "select leftcount  from " + main.g_space + ".VIEW_SQL_PL_LOC where inv_org = '" + main.g_org + "' and location_code='" + str_outloc + "'";
            if (main.dbtype == "SQL")
            {
                ds_str = main.dbservice.Sql_exec_selectsql(str);
            }
            else
            {
                ds_str = main.dbservice.oracle_exec_selectsql(str);
            }
            if (ds_str.Tables[0].Rows.Count > 0)
            {
                if (Convert.ToDecimal(ds_str.Tables[0].Rows[0][0]) < d_outqty )//判断库位是否可用
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("" + str_outloc + "Location code lack of capacity can not be moved sku!", main.g_info_dataset) + "!");
                    return;
                }
            }
        }
        
        private void cb_consignor_TextChanged(object sender, EventArgs e)
        {
            string str_cust;
            str_cust = cb_consignor.Text.Trim();
            tb_cusname.Text = main.g_class.comm_findname(str_cust, dscustomer);
        }

        private void show(DataRow tr)
        {
            
            this.cbx_h_consignor.Text = tr["consignor"].ToString().Trim();
            this.tb_h_consignor_name.Text = tr["consignor_name"].ToString().Trim();
            this.cb_move_type.SelectedIndex = Convert.ToInt32(tr["replenish_type"].ToString().Trim());
            this.cb_h_move_status.SelectedValue = tr["replenish_status"].ToString().Trim();
            // this.cbx_h_move_reason.SelectedValue = Convert.ToInt32(tr["move_reason"].ToString().Trim());

            this.tb_h_move_no.Text = tr["replenish_no"].ToString().Trim();
            this.tb_h_memo.Text = tr["memo"].ToString().Trim();
        }

        private void btn_Query_Click(object sender, EventArgs e)
        {
            string where1 = "";
            string where2 = "";
            string str_sql = "";
            str_sql_where = " where a.inv_org = '"+main.g_org+"' and a.move_type='2' and  a.main_dist<>'D' ";
            if (cb_consignor.Text.ToString().Trim() != "")
            {
                str_sql_where += " and a.consignor='" + cb_consignor.Text.ToString().Trim() + "' ";
            }
            else
            {
                str_sql_where += " and  a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '"+main.g_org+"' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
            }
            if (tb_move_no.Text.ToString().Trim() != "")
            {
                str_sql_where += " and a.move_no='" + tb_move_no.Text.ToString().Trim() + "' ";
            }
            if (dtp_made_time.Text.ToString().Trim() != "" | dtp_made_time_end.Text.ToString().Trim() != "")
            {
                if (main.dbtype == "SQL")
                    str_sql_where += " and  CONVERT(varchar(10) , a.made_time, 102 )  between     '" + dtp_made_time.Text.Trim() + "' and '" + dtp_made_time_end.Text + "'";
                else
                    str_sql_where += " and to_char(a.made_time,'yyyy.mm.dd')  between     '" + dtp_made_time.Text.Trim() + "' and '" + dtp_made_time_end.Text + "'";    
            }
            if (cb_q_status.SelectedIndex > -1)
            {
                str_sql_where += " and a.move_status='" + cb_q_status.SelectedIndex + "'";
            }
            str_sql = "select consignor_name,a.consignor,a.move_no as replenish_no ,case a.move_status when '0' then '" + main.g_class.comm_getchangestring("make", main.g_info_dataset) + "' " +
            "when '1' then '" + main.g_class.comm_getchangestring("part confirm", main.g_info_dataset) + "'when '2' then '" + main.g_class.comm_getchangestring("confirm", main.g_info_dataset) + "'" +
            "else  '" + main.g_class.comm_getchangestring("close", main.g_info_dataset) + "'end as replenish_status,a.move_type as replenish_type,a.move_reason as replenish_reason,a.wave_dist,a.wave_no,a.standby_1,a.standby_2,a.standby_3,a.standby_4," +
            "a.standby_5,a.standby_6,a.standby_7,a.confirm_day,a.confirmer,a.memo,a.main_dist,a.maker,a.made_time,a.move_no,a.move_status from " + main.g_space + ".inv_move_header  a left join wms.mst_customer b on a.inv_org = b.inv_org and b.consignor=a.consignor " + str_sql_where;
            
            try
            {
                dsmove_header = new DataSet();
                if (main.dbtype == "SQL")
                {
                    dsmove_header = main.dbservice.Sql_exec_selectsql(str_sql);
                }
                else
                {
                    dsmove_header = main.dbservice.oracle_exec_selectsql(str_sql);
                }
                dataGridView1.DataSource = dsmove_header.Tables[0];
                if (dsmove_header.Tables[0].Rows.Count > 0)
                {
                    dsmove_detail = new DataSet();
                    show(dsmove_header.Tables[0].Rows[0]);
                    if (str_type == "0")
                    {
                        str_sql = "select inv_org,consignor,move_no as replenish_no,move_line_no as replenish_line_no,moveout_location as replenishout_location,moveout_pallet as replenishout_pallet,batchno,sku,sku_name," +
                              "pack_code,main_sub_flag,convert_modulus,movein_location as replenishin_location,movein_pallet as replenishin_pallet,stock_qty_m,stock_qty_s,move_qty_m as replenish_qty_m," +
                              "move_qty_s as replenish_qty_s,tmp_qty_m,tmp_qty_s,confirm_qty_m,confirm_qty_s,cubage,gross_weight,net_weight,move_cubage as replenish_cubage,move_gross_weight as replenish_gross_weight," +
                              "move_net_weight as replenish_net_weight,confirm_cubage,confirm_gross_weight,confirm_net_weight,standby_1,standby_2,standby_3,standby_4,standby_5," +
                              "standby_6,standby_7,move_status as replenish_status,confirm_dist,confirm_day,confirmer,main_dist,made_time,maker,update_time,updater,so_no,so_line_no,ext_dist,ext_batchno," +
                            "confirm_qty_m as old_confirm_qty_m,move_no,move_line_no"+
                              " ,lot_attribute1,lot_attribute2,lot_attribute3,lot_attribute4,lot_attribute5,lot_attribute6," +
                             " lot_attribute7,lot_attribute8,lot_attribute9,lot_attribute10,lot_attribute11,lot_attribute12,lot_attribute13,lot_attribute14,lot_attribute15  " + 
                            " from " + main.g_space + ".inv_move_detail where inv_org = '" + main.g_org + "' and move_no='" + dsmove_header.Tables[0].Rows[0]["replenish_no"].ToString().Trim() + "' and consignor='" + dsmove_header.Tables[0].Rows[0]["consignor"].ToString().Trim() + "'";

                        move_no_str = dsmove_header.Tables[0].Rows[0]["replenish_no"].ToString().Trim();
                        dsmove_mv = new DataSet();
                        dsmove_con = new DataSet();

                        where1 = " and moveout_pallet='0' and batchno='0' ";
                        where2 = " and moveout_pallet<>'0' and batchno<>'0' ";
                    }
                    else
                    {
                        str_updatesql = "select inv_org,consignor,move_no as replenish_no,move_line_no as replenish_line_no,moveout_location as replenishout_location,moveout_pallet as replenishout_pallet,batchno,sku,sku_name," +
                              "pack_code,main_sub_flag,convert_modulus,movein_location as replenishin_location,movein_pallet as replenishin_pallet,stock_qty_m,stock_qty_s,move_qty_m as replenish_qty_m," +
                              "move_qty_s as replenish_qty_s,tmp_qty_m,tmp_qty_s,confirm_qty_m,confirm_qty_s,cubage,gross_weight,net_weight,move_cubage as replenish_cubage,move_gross_weight as replenish_gross_weight," +
                              "move_net_weight as replenish_net_weight,confirm_cubage,confirm_gross_weight,confirm_net_weight,standby_1,standby_2,standby_3,standby_4,standby_5," +
                              "standby_6,standby_7,move_status as replenish_status,confirm_dist,confirm_day,confirmer,main_dist,made_time,maker,update_time,updater,so_no,so_line_no,ext_dist,ext_batchno," +
                            "confirm_qty_m as old_confirm_qty_m,move_no,move_line_no "+
                              " ,lot_attribute1,lot_attribute2,lot_attribute3,lot_attribute4,lot_attribute5,lot_attribute6," +
                             " lot_attribute7,lot_attribute8,lot_attribute9,lot_attribute10,lot_attribute11,lot_attribute12,lot_attribute13,lot_attribute14,lot_attribute15  " + 
                            " from " + main.g_space + ".inv_move_detail where inv_org = '" + main.g_org + "' and move_no='" + dsmove_header.Tables[0].Rows[0]["replenish_no"].ToString().Trim() + "' and consignor='" + dsmove_header.Tables[0].Rows[0]["consignor"].ToString().Trim() + "'";

                        str_sql = "select a.inv_org,a.consignor,move_no as replenish_no,move_line_no as replenish_line_no,moveout_location as replenishout_location,"+
                                   " moveout_pallet as replenishout_pallet,a.batchno,a.sku,sku_name,a.pack_code,a.main_sub_flag,a.convert_modulus,movein_location as replenishin_location,"+
                                   " movein_pallet as replenishin_pallet,a.stock_qty_m,a.stock_qty_s,move_qty_m as replenish_qty_m,move_qty_s as replenish_qty_s,tmp_qty_m,tmp_qty_s,"+
                                   " a.confirm_qty_m,a.confirm_qty_s,a.cubage,a.gross_weight,a.net_weight,move_cubage as replenish_cubage,move_gross_weight as replenish_gross_weight,"+
                                   " move_net_weight as replenish_net_weight,confirm_cubage,confirm_gross_weight,confirm_net_weight,a.standby_1,a.standby_2,a.standby_3,a.standby_4,a.standby_5,"+
                                   " a.standby_6,a.standby_7,move_status as replenish_status,a.confirm_dist,a.confirm_day,a.confirmer,a.main_dist,a.made_time,a.maker,a.update_time,a.updater,so_no,"+
                                   " so_line_no,ext_dist,ext_batchno,confirm_qty_m as old_confirm_qty_m,move_no,move_line_no,a.lot_attribute1,a.lot_attribute2,a.lot_attribute3,a.lot_attribute4,a.lot_attribute5,a.lot_attribute6,"+
                                    " a.lot_attribute7,a.lot_attribute8,a.lot_attribute9,a.lot_attribute10,a.lot_attribute11,a.lot_attribute12,a.lot_attribute13,a.lot_attribute14,a.lot_attribute15  "+ 
                                   " from " + main.g_space + ".inv_move_detail a where a.inv_org = '" + main.g_org + "' and a.move_no='" + dsmove_header.Tables[0].Rows[0]["replenish_no"].ToString().Trim() + "' and a.consignor='" + dsmove_header.Tables[0].Rows[0]["consignor"].ToString().Trim() + "' ";

                        move_no_str = dsmove_header.Tables[0].Rows[0]["replenish_no"].ToString().Trim();
                        dsmove_mv = new DataSet();
                        dsmove_con = new DataSet();
                        
                         where1 = " ";
                         where2 = " and a.move_status in ('1','2')  ";
                    }
                    if (main.dbtype == "SQL")   
                    {    
                        str_sql_mv = str_sql + where1;
                        dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                        str_sql_con = str_sql + where2;
                        dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);
                    }
                    else
                    {
                        str_sql_mv = str_sql + where1;
                        dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                        str_sql_con = str_sql + where2;
                        dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                    }
                    dataGridView2.DataSource = dsmove_mv.Tables[0];
                    dataGridView3.DataSource = dsmove_con.Tables[0];
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to Query", main.g_info_dataset) + "!" + ee.ToString());
            } 

        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string str_sql = "";
      
            string where1 = "";
            string where2 = "";
            where1 = " and moveout_pallet='0' and batchno='0' ";
            where2 = " and moveout_pallet<>'0' and batchno<>'0'";
            move_no_str = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["replenish_no"].Value.ToString().Trim();
            str_sql_where = "consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' and move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["replenish_no"].Value.ToString().Trim() + "'";
           //取确认状态
            g_str_status = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["replenish_status"].Value.ToString().Trim();
            g_str_status = main.g_class.comm_getconversestring(g_str_status, main.g_info_dataset);
            switch (g_str_status.Trim().ToLower())
            {
                case "make":
                    g_str_status = "0";
                    break;
                case "part confirm":
                    g_str_status = "1";
                    break;
                case "confirm":
                    g_str_status = "2";
                    break;
                case "close":
                    g_str_status = "3";
                    break;
                default:
                    g_str_status = "";
                    break;
            }
            DataRow[] tr_header = dsmove_header.Tables[0].Select(str_sql_where);

            if (tr_header.Length > 0)
            {
                show(tr_header[0]);
                if (str_type == "0")
                {
                    dsmove_mv = new DataSet();
                    dsmove_con = new DataSet();
                    str_sql = "select inv_org,consignor,move_no as replenish_no,move_line_no as replenish_line_no,moveout_location as replenishout_location,moveout_pallet as replenishout_pallet,batchno,sku,sku_name," +
                              "pack_code,main_sub_flag,convert_modulus,movein_location as replenishin_location,movein_pallet as replenishin_pallet,stock_qty_m,stock_qty_s,move_qty_m as replenish_qty_m," +
                              "move_qty_s as replenish_qty_s,tmp_qty_m,tmp_qty_s,confirm_qty_m,confirm_qty_s,cubage,gross_weight,net_weight,move_cubage as replenish_cubage,move_gross_weight as replenish_gross_weight," +
                              "move_net_weight as replenish_net_weight,confirm_cubage,confirm_gross_weight,confirm_net_weight,standby_1,standby_2,standby_3,standby_4,standby_5," +
                              "standby_6,standby_7,move_status as replenish_status,confirm_dist,confirm_day,confirmer,main_dist,made_time,maker,update_time,updater,so_no,so_line_no,ext_dist,ext_batchno," +
                              "confirm_qty_m as old_confirm_qty_m,move_no,move_line_no"+
                                " ,lot_attribute1,lot_attribute2,lot_attribute3,lot_attribute4,lot_attribute5,lot_attribute6," +
                             " lot_attribute7,lot_attribute8,lot_attribute9,lot_attribute10,lot_attribute11,lot_attribute12,lot_attribute13,lot_attribute14,lot_attribute15  " + 
                              " from " + main.g_space + ".inv_move_detail where inv_org = '" + main.g_org + "' and " + str_sql_where;
                    if (main.dbtype == "SQL")
                    {
                        str_sql_mv = str_sql + where1;
                        dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                        str_sql_con = str_sql + where2;
                        dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);
                    }
                    else
                    {
                        str_sql_mv = str_sql + where1;
                        dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                        str_sql_con = str_sql + where2;
                        dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                    }
                    dataGridView2.DataSource = dsmove_mv.Tables[0];
                    dataGridView3.DataSource = dsmove_con.Tables[0];
                }
                else//分配到托盘批次
                {
                    dsmove_mv = new DataSet();
                    dsmove_con = new DataSet();
                    str_sql = "select a.inv_org,a.consignor,move_no as replenish_no,move_line_no as replenish_line_no,moveout_location as replenishout_location," +
                                 " moveout_pallet as replenishout_pallet,a.batchno,a.sku,sku_name,a.pack_code,a.main_sub_flag,a.convert_modulus,movein_location as replenishin_location," +
                                 " movein_pallet as replenishin_pallet,a.stock_qty_m,a.stock_qty_s,move_qty_m as replenish_qty_m,move_qty_s as replenish_qty_s,tmp_qty_m,tmp_qty_s," +
                                 " a.confirm_qty_m,a.confirm_qty_s,a.cubage,a.gross_weight,a.net_weight,move_cubage as replenish_cubage,move_gross_weight as replenish_gross_weight," +
                                 " move_net_weight as replenish_net_weight,confirm_cubage,confirm_gross_weight,confirm_net_weight,a.standby_1,a.standby_2,a.standby_3,a.standby_4,a.standby_5," +
                                 " a.standby_6,a.standby_7,move_status as replenish_status,a.confirm_dist,a.confirm_day,a.confirmer,a.main_dist,a.made_time,a.maker,a.update_time,a.updater,so_no," +
                                 " so_line_no,ext_dist,ext_batchno,confirm_qty_m as old_confirm_qty_m,move_no,move_line_no"+
                                 ",lot_attribute1,lot_attribute2,lot_attribute3,lot_attribute4,lot_attribute5,lot_attribute6," +
                                  " lot_attribute7,lot_attribute8,lot_attribute9,lot_attribute10,lot_attribute11,lot_attribute12,lot_attribute13,lot_attribute14,lot_attribute15  " +
                                 " from " + main.g_space + ".inv_move_detail a where a.inv_org = '" + main.g_org + "' and a.move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["replenish_no"].Value.ToString().Trim() + "' and a.consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' ";
               
                   
                    str_updatesql = "select inv_org,consignor,move_no as replenish_no,move_line_no as replenish_line_no,moveout_location as replenishout_location,moveout_pallet as replenishout_pallet,batchno,sku,sku_name," +
                              "pack_code,main_sub_flag,convert_modulus,movein_location as replenishin_location,movein_pallet as replenishin_pallet,stock_qty_m,stock_qty_s,move_qty_m as replenish_qty_m," +
                              "move_qty_s as replenish_qty_s,tmp_qty_m,tmp_qty_s,confirm_qty_m,confirm_qty_s,cubage,gross_weight,net_weight,move_cubage as replenish_cubage,move_gross_weight as replenish_gross_weight," +
                              "move_net_weight as replenish_net_weight,confirm_cubage,confirm_gross_weight,confirm_net_weight,standby_1,standby_2,standby_3,standby_4,standby_5," +
                              "standby_6,standby_7,move_status as replenish_status,confirm_dist,confirm_day,confirmer,main_dist,made_time,maker,update_time,updater,so_no,so_line_no,ext_dist,ext_batchno," +
                              "confirm_qty_m as old_confirm_qty_m,move_no,move_line_no"+
                               ",lot_attribute1,lot_attribute2,lot_attribute3,lot_attribute4,lot_attribute5,lot_attribute6," +
                                  " lot_attribute7,lot_attribute8,lot_attribute9,lot_attribute10,lot_attribute11,lot_attribute12,lot_attribute13,lot_attribute14,lot_attribute15  " +
                              " from " + main.g_space + ".inv_move_detail where inv_org = '" + main.g_org + "' and  move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["replenish_no"].Value.ToString().Trim() + "' and consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' ";
                    where1 = " ";
                    where2 = " and a.move_status in ('1','2')  ";
                    if (main.dbtype == "SQL")
                    {
                        str_sql_mv = str_sql + where1;
                        dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                        str_sql_con = str_sql + where2;
                        dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);
                    }
                    else
                    {
                        str_sql_mv = str_sql + where1;
                        dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                        str_sql_con = str_sql + where2;
                        dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                    }
                    dataGridView2.DataSource = dsmove_mv.Tables[0];
                    dataGridView3.DataSource = dsmove_con.Tables[0];
                }
            }
        }

        private void bt_Direction_Click(object sender, EventArgs e)
        {
            //this.dataGridView2.ReadOnly = false;
            
            if (g_str_status=="3")     
                return;
           
            if (dsmove_mv == null || dsmove_mv.Tables[0].Rows.Count <=  0) //20140828 添加 表格里无数据时，直接退出
            {
                return;
            }
           
            for (int i = 0; i < dsmove_mv.Tables[0].Rows.Count; i++)
            {
                if (dsmove_mv.Tables[0].Rows[i]["confirm_qty_m"].ToString().Trim() == null || dsmove_mv.Tables[0].Rows[i]["confirm_qty_m"].ToString().Trim() == "")
                {
                    dsmove_mv.Tables[0].Rows[i]["confirm_qty_m"] = 0;
                }

                if ((Convert.ToDecimal(dsmove_mv.Tables[0].Rows[i]["replenish_qty_m"]) - Convert.ToDecimal(dsmove_mv.Tables[0].Rows[i]["confirm_qty_m"].ToString().Trim())) > 0)
                {
                    dsmove_mv.Tables[0].Rows[i]["tmp_qty_m"] = (Convert.ToDecimal(dsmove_mv.Tables[0].Rows[i]["replenish_qty_m"].ToString().Trim()) - Convert.ToDecimal(dsmove_mv.Tables[0].Rows[i]["confirm_qty_m"].ToString().Trim()));
                }
                else
                {
                    dsmove_mv.Tables[0].Rows[i]["tmp_qty_m"] = 0;
                }
            }
            g_str_oper = 2;
            this.bt_Confirm.Enabled = true;
            this.bt_Cancel.Enabled = true;
            this.bt_Close.Enabled = false;
        }

        private void bt_Cancel_Click(object sender, EventArgs e)
        {
            string str_sql = "";
            string where1 = "";
            string where2 = "";
            where1 = " and moveout_pallet='0' and batchno='0' and  move_status='0'";
            where2 = " and moveout_pallet<>'0' and batchno<>'0'";
            move_no_str = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["replenish_no"].Value.ToString().Trim();
            str_sql_where = "consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' and move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no"].Value.ToString().Trim() + "'";
            DataRow[] tr_header = dsmove_header.Tables[0].Select(str_sql_where);

            if (tr_header.Length > 0)
            {
                show(tr_header[0]);
                if (str_type == "0")
                {
                    dsmove_mv = new DataSet();
                    dsmove_con = new DataSet();
                    str_sql = "select inv_org,consignor,move_no as replenish_no,move_line_no as replenish_line_no,moveout_location as replenishout_location,moveout_pallet as replenishout_pallet,batchno,sku,sku_name," +
                              "pack_code,main_sub_flag,convert_modulus,movein_location as replenishin_location,movein_pallet as replenishin_pallet,stock_qty_m,stock_qty_s,move_qty_m as replenish_qty_m," +
                              "move_qty_s as replenish_qty_s,tmp_qty_m,tmp_qty_s,confirm_qty_m,confirm_qty_s,cubage,gross_weight,net_weight,move_cubage as replenish_cubage,move_gross_weight as replenish_gross_weight," +
                              "move_net_weight as replenish_net_weight,confirm_cubage,confirm_gross_weight,confirm_net_weight,standby_1,standby_2,standby_3,standby_4,standby_5," +
                              "standby_6,standby_7,move_status as replenish_status,confirm_dist,confirm_day,confirmer,main_dist,made_time,maker,update_time,updater,so_no,so_line_no,ext_dist,ext_batchno," +
                              "confirm_qty_m as old_confirm_qty_m,move_no,move_line_no from " + main.g_space + ".inv_move_detail where inv_org = '" + main.g_org + "' and " + str_sql_where;
                    try
                    {
                        if (main.dbtype == "SQL")
                        {
                            str_sql_mv = str_sql + where1;
                            dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                            str_sql_con = str_sql + where2;
                            dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);
                        }
                        else
                        {
                            str_sql_mv = str_sql + where1;
                            dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                            str_sql_con = str_sql + where2;
                            dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                        }
                        dataGridView2.DataSource = dsmove_mv.Tables[0];
                        dataGridView3.DataSource = dsmove_con.Tables[0];
                        g_str_oper = 0;
                        this.bt_Close.Enabled = true;
                        this.bt_Direction.Enabled = true;
                        this.bt_Confirm.Enabled = false;
                        this.bt_Cancel.Enabled = false;
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else//分配到批次托盘
                {
                    dsmove_mv = new DataSet();
                    dsmove_con = new DataSet();
                    str_sql = "select a.inv_org,a.consignor,move_no as replenish_no,move_line_no as replenish_line_no,moveout_location as replenishout_location," +
                                " moveout_pallet as replenishout_pallet,a.batchno,a.sku,sku_name,a.pack_code,a.main_sub_flag,a.convert_modulus,movein_location as replenishin_location," +
                                " movein_pallet as replenishin_pallet,a.stock_qty_m,a.stock_qty_s,move_qty_m as replenish_qty_m,move_qty_s as replenish_qty_s,tmp_qty_m,tmp_qty_s," +
                                " a.confirm_qty_m,a.confirm_qty_s,a.cubage,a.gross_weight,a.net_weight,move_cubage as replenish_cubage,move_gross_weight as replenish_gross_weight," +
                                " move_net_weight as replenish_net_weight,confirm_cubage,confirm_gross_weight,confirm_net_weight,a.standby_1,a.standby_2,a.standby_3,a.standby_4,a.standby_5," +
                                " a.standby_6,a.standby_7,move_status as replenish_status,a.confirm_dist,a.confirm_day,a.confirmer,a.main_dist,a.made_time,a.maker,a.update_time,a.updater,so_no," +
                                " so_line_no,ext_dist,ext_batchno,confirm_qty_m as old_confirm_qty_m,move_no,move_line_no"+
                                ",lot_attribute1,lot_attribute2,lot_attribute3,lot_attribute4,lot_attribute5,lot_attribute6," +
                                 " lot_attribute7,lot_attribute8,lot_attribute9,lot_attribute10,lot_attribute11,lot_attribute12,lot_attribute13,lot_attribute14,lot_attribute15  " +
                                " from " + main.g_space + ".inv_move_detail a where a.inv_org = '" + main.g_org + "' and a.move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no"].Value.ToString().Trim() + "' and a.consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' ";
                   
                    
                    str_updatesql = "select inv_org,consignor,move_no as replenish_no,move_line_no as replenish_line_no,moveout_location as replenishout_location,moveout_pallet as replenishout_pallet,batchno,sku,sku_name," +
                              "pack_code,main_sub_flag,convert_modulus,movein_location as replenishin_location,movein_pallet as replenishin_pallet,stock_qty_m,stock_qty_s,move_qty_m as replenish_qty_m," +
                              "move_qty_s as replenish_qty_s,tmp_qty_m,tmp_qty_s,confirm_qty_m,confirm_qty_s,cubage,gross_weight,net_weight,move_cubage as replenish_cubage,move_gross_weight as replenish_gross_weight," +
                              "move_net_weight as replenish_net_weight,confirm_cubage,confirm_gross_weight,confirm_net_weight,standby_1,standby_2,standby_3,standby_4,standby_5," +
                              "standby_6,standby_7,move_status as replenish_status,confirm_dist,confirm_day,confirmer,main_dist,made_time,maker,update_time,updater,so_no,so_line_no,ext_dist,ext_batchno," +
                              "confirm_qty_m as old_confirm_qty_m,move_no,move_line_no"+
                              ",lot_attribute1,lot_attribute2,lot_attribute3,lot_attribute4,lot_attribute5,lot_attribute6," +
                                 " lot_attribute7,lot_attribute8,lot_attribute9,lot_attribute10,lot_attribute11,lot_attribute12,lot_attribute13,lot_attribute14,lot_attribute15  " +
                              " from " + main.g_space + ".inv_move_detail where inv_org = '" + main.g_org + "' and consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' and move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no"].Value.ToString().Trim() + "'";
                    where1 = " ";
                    where2 = " and a.move_status in ('1','2')  ";
                    try
                    {
                        if (main.dbtype == "SQL")
                        {
                            str_sql_mv = str_sql + where1;
                            dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                            str_sql_con = str_sql + where2;
                            dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);
                        }
                        else
                        {
                            str_sql_mv = str_sql + where1;
                            dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                            str_sql_con = str_sql + where2;
                            dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                        }
                        dataGridView2.DataSource = dsmove_mv.Tables[0];
                        dataGridView3.DataSource = dsmove_con.Tables[0];
                        g_str_oper = 0;
                        this.bt_Close.Enabled = true;
                        this.bt_Direction.Enabled = true;
                        this.bt_Confirm.Enabled = false;
                        this.bt_Cancel.Enabled = false;
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }

        private void bt_Confirm_Click(object sender, EventArgs e)
        {
            if (g_str_status == "3")
                return;
            try
            {
                string aa="";
                if (str_type == "0")
                {
                    if (main.dbtype == "SQL")
                        aa = main.dbservice.Sql_reple_confirm(main.g_org, dsmove_mv, str_sql_mv, this.cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                    else
                        aa = main.dbservice.oracle_reple_confirm(main.g_org, dsmove_mv, str_sql_mv, this.cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                    if (aa != "0")
                        MessageBox.Show(aa);
                }
                else
                {
                    if (main.dbtype == "SQL")
                        aa = main.dbservice.Sql_reple_confirm(main.g_org, dsmove_mv, str_updatesql, this.cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                    else
                        aa = main.dbservice.oracle_reple_confirm(main.g_org, dsmove_mv, str_updatesql, this.cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                    if (aa != "0")
                        MessageBox.Show(aa);
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to comfirm", main.g_info_dataset) + "!" + ee.ToString().Trim());
                Cursor.Current = Cursors.Default;
                return;
            }
            //刷新补货信息
            btn_Query_Click(sender, new EventArgs());
            g_str_oper = 0;
            this.bt_Confirm.Enabled = false;
            this.bt_Cancel.Enabled = false;
            this.bt_Close.Enabled = true;

            MessageBox.Show("确认完成");
            Cursor.Current = Cursors.Default;
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (g_str_oper== 1)
            {
                tabControl1.SelectedIndex = 1;
                return;
            }
            else if (g_str_oper == 2)
            {
                if (bt_Confirm.Enabled == true)
                {
                    tabControl1.SelectedIndex = 0;
                }
            }
        }

        private void dataGridView3_DoubleClick(object sender, EventArgs e)
        {
            
            if (g_str_oper == 1)
            {
                if (dataGridView3.CurrentRow != null)  //说明有选中的行有效
                {
                   
                    if (System.Convert.ToInt32(dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_replenish_line_no"].Value.ToString().Trim()) == g_line_no)
                    {
                        string str_name;
                        str_name = dataGridView3.Columns[dataGridView3.CurrentCell.ColumnIndex].Name.ToString().Trim();
                        if (str_name == "E_replenishout_pallet" || str_name == "E_batchno")
                        {
                            dt_save.Clear(); 
                            DataRow drrow = dt_save.NewRow();
                            drrow["inv_org"] = main.g_org;
                            drrow["consignor"] = this.cbx_h_consignor.Text.Trim();
                            drrow["so_no"] = "";
                            drrow["so_line_no"] = "";
                            drrow["sku"] = (string)dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_sku"].Value.ToString();
                            drrow["location_code"] = (string)dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_replenishout_location"].Value.ToString();
                            drrow["qty"] = "0";
                            drrow["n_ea_cubage"] = "0";
                            drrow["n_ea_gross"] = "0";
                            drrow["n_ea_net"] = "0";
                            //drrow["old_qty"] = (string)dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["Old_confirm_qty_m"].Value.ToString();
                            drrow["old_qty"] = L_qty.ToString();
                            dt_save.Rows.Add(drrow);
                            w_so014_loc w_so014_loc = new w_so014_loc();
                            w_so014_loc.ShowDialog();
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["batchno"] = dt_save.Rows[0]["so_no"].ToString();
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["replenishout_pallet"] = dt_save.Rows[0]["so_line_no"].ToString();
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["replenishin_pallet"] = dt_save.Rows[0]["so_line_no"].ToString();

                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_cubage"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_cubage"].ToString().Trim()), 4);
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_gross_weight"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_gross"].ToString().Trim()), 4);
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_net_weight"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_net"].ToString().Trim()), 4);
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_qty_m"] = dt_save.Rows[0]["qty"].ToString();
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_qty_s"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["convert_modulus"]), 4);
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["Old_confirm_qty_m"] = dt_save.Rows[0]["old_qty"].ToString();
                            g_round = 1;
                        }

                    }
                    else
                        return;

                }
            }

        }

        private void dataGridView3_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            string str_name;
            string sp_csgo, sp_move_no, p_sku, sp_loc, sp_bat, sp_in_pallet;
            int i_temp, sp_line_no, i_found;
            sp_csgo = cbx_h_consignor.Text.Trim();
            if (e.RowIndex != -1)  //说明有选中的行有效
            {
                i_temp = dataGridView3.CurrentRow.Index;
                
                str_name = dataGridView3.Columns[dataGridView3.CurrentCell.ColumnIndex].Name.ToString().Trim();
                if (str_name == "E_confirm_qty_m" || str_name == "E_replenishin_pallet")
                {
                    if (g_str_oper == 1 && g_round == 1) //说明是新增,只允许对新增行编辑
                    {
                        if (System.Convert.ToDecimal(dataGridView3.Rows[dataGridView3.RowCount - 1].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()) >  System.Convert.ToDecimal(dt_save.Rows[0]["old_qty"])) //说明超过可用数量
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("The quantity of inputting more than available quantity", main.g_info_dataset) + ":" + dataGridView3.Rows[dataGridView3.RowCount - 1].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim());
                            dt_save.Rows[0]["qty"] = "0";
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_cubage"] = 0;
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_gross_weight"] = 0;
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_net_weight"] = 0;
                            dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = false;
                            dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = true;
                            return;
                        }
                        else
                        {
                            dt_save.Rows[0]["qty"] = System.Convert.ToString(Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()), 4));
                            //((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_cubage"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_cubage"].ToString().Trim()), 4);
                            //((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_gross_weight"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_gross"].ToString().Trim()), 4);
                            //((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_net_weight"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_net"].ToString().Trim()), 4);
                        }
                       
                    dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = false;
                    dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = true;

                }
                else if (g_str_oper == 2)   //说明是修改
                {
                    i_temp = dataGridView3.CurrentRow.Index;
                    
                    sp_move_no = tb_h_move_no.Text.Trim();

                    sp_line_no = System.Convert.ToInt32(dataGridView3.Rows[i_temp].Cells["E_replenish_line_no"].EditedFormattedValue.ToString().Trim());
                    p_sku = (string)dataGridView3.Rows[i_temp].Cells["E_sku"].EditedFormattedValue.ToString().Trim();
                    sp_loc = (string)dataGridView3.Rows[i_temp].Cells["E_replenishout_location"].EditedFormattedValue.ToString().Trim();
                    sp_bat = (string)dataGridView3.Rows[i_temp].Cells["E_batchno"].EditedFormattedValue.ToString().Trim();
                    sp_in_pallet = (string)dataGridView3.Rows[i_temp].Cells["E_replenishin_pallet"].EditedFormattedValue.ToString().Trim();
                   // sp_qty = dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim();
                    if (System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()) > System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim())) //说明超过可用数量
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("The quantity of inputting more than available quantity", main.g_info_dataset) + ":" + dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim());
                        //寻找dt_save相应的行号，返回-1说明没有直接改dg_allocate
                        i_found = f_get_save_index(sp_csgo, sp_move_no, sp_line_no.ToString(), sp_loc);
                        if (i_found != -1) dt_save.Rows[i_found]["qty"] = "0";
                        i_found = f_get_table_index(sp_csgo, sp_move_no, sp_line_no.ToString(), sp_loc);
                        ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.RowCount - 1]["confirm_cubage"] = 0;
                        ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.RowCount - 1]["confirm_gross_weight"] = 0;
                        ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.RowCount - 1]["confirm_net_weight"] = 0;
                        dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = false;
                        dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = true;
                        return;
                    }
                    else //不超过
                    {
                        //寻找dt_save相应的行号，返回-1说明没有直接改dg_allocate
                        i_found = f_get_save_index(sp_csgo, sp_move_no, sp_line_no.ToString(), sp_loc);
                        if (i_found != -1)  //说明有信息,修改
                            modify.Rows[i_found]["qty"] = System.Convert.ToString(Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()), 4));
                        else //没有信息，新增
                        {
                            DataRow drrow = modify.NewRow();
                            drrow["old_qty"] =System.Convert.ToString(Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim()), 4)); 
                            drrow["qty"] =System.Convert.ToString(Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()), 4));
                            drrow["inv_org"] = main.g_org;
                            drrow["consignor"] =sp_csgo;
                            drrow["move_no"] =sp_move_no;
                            drrow["move_line_no"] = System.Convert.ToInt32(dataGridView3.Rows[i_temp].Cells["E_replenish_line_no"].EditedFormattedValue.ToString().Trim());
                            drrow["sku"] =System.Convert.ToString(Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_sku"].EditedFormattedValue.ToString().Trim()), 4));
                            drrow["location_code"] = System.Convert.ToString(dataGridView3.Rows[i_temp].Cells["E_replenishout_location"].EditedFormattedValue.ToString().Trim());
                            drrow["batch_no"] = System.Convert.ToString(dataGridView3.Rows[i_temp].Cells["E_batchno"].EditedFormattedValue.ToString().Trim());
                            drrow["pallet_no"] = System.Convert.ToString(dataGridView3.Rows[i_temp].Cells["E_replenishout_pallet"].EditedFormattedValue.ToString().Trim());
                            drrow["in_pallet_no"] = System.Convert.ToString(dataGridView3.Rows[i_temp].Cells["E_replenishin_pallet"].EditedFormattedValue.ToString().Trim());                 
                            modify.Rows.Add(drrow);
                        }
                        i_found = f_get_table_index(sp_csgo, sp_move_no, sp_line_no.ToString(), sp_loc);
                        ((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_qty_m"] = Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()), 4);
                        ((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_qty_s"] = Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()) * (System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_s"].EditedFormattedValue.ToString().Trim()) / System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim())), 4);
                        ((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_cubage"] = Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()) * (System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_cubage"].EditedFormattedValue.ToString().Trim()) / System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim())), 4);
                        ((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_gross_weight"] = Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()) * (System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_gross_weight"].EditedFormattedValue.ToString().Trim()) / System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim())), 4);
                        //((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_net_weight"] = Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()) * (System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_net_weight"].EditedFormattedValue.ToString().Trim()) / System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim())), 4);
                    }
                    dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = false;
                    dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = true;

                }
                   
                }
            }
        }
        private Int32 f_get_table_index(string str_con, string str_so, string str_line, string str_loc)
        {
            if (((DataTable)dataGridView3.DataSource).Rows.Count > 0) //说明有数据查找
            {
                int i;
                for (i = 0; i < ((DataTable)dataGridView3.DataSource).Rows.Count; i++)
                {
                    if (((DataTable)dataGridView3.DataSource).Rows[i]["consignor"].ToString().Trim() == str_con && ((DataTable)dataGridView3.DataSource).Rows[i]["replenish_no"].ToString().Trim() == str_so && ((DataTable)dataGridView3.DataSource).Rows[i]["replenish_line_no"].ToString().Trim() == str_line && ((DataTable)dataGridView3.DataSource).Rows[i]["replenishout_location"].ToString().Trim() == str_loc)  //找到
                        return i;
                }
                return -1;
            }
            else
                return -1;
        }
        private Int32 f_get_save_index(string str_con, string move_no, string str_line, string str_loc)
        {
            if (dt_save.Rows.Count > 0) //说明有数据查找
            {
                int i;
                for (i = 0; i < dt_save.Rows.Count; i++)
                {
                    if (modify.Rows[i]["consignor"].ToString().Trim() == str_con && modify.Rows[i]["replenish_no"].ToString().Trim() == move_no && modify.Rows[i]["replenish_line_no"].ToString().Trim() == str_line && modify.Rows[i]["location_code"].ToString().Trim() == str_loc)  //找到
                        return i;
                }
                return -1;
            }
            else
                return -1;
        }
        private void btn_save_Click(object sender, EventArgs e)
        {
            string str_ren;
            str_ren = "";
           
            Cursor.Current = Cursors.WaitCursor;
            if (g_str_oper == 1) //说明是新增
            {
                if (System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) != 0)
                {
                            string s_consignor=cbx_h_consignor.Text.Trim();
                             string s_move_no=tb_h_move_no.Text.Trim();
                             int i_line = System.Convert.ToInt32(((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["replenish_line_no"]);
                             string s_outloc = (string)((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["replenishout_location"];
                             string s_inloc = (string)((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["replenishin_location"];
                             string s_pallet = (string)((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["replenishout_pallet"];
                             string s_inpallet = (string)((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["replenishin_pallet"];
                             string s_bat = (string)((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["batchno"];
                             decimal d_qty=Math.Round( System.Convert.ToDecimal(((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count-1]["confirm_qty_m"]),4);
                             decimal d_pallet_qty;
                             //判断托盘数量
                             string s_sql;
                              DataSet dt_pallet;
                              if(main.dbtype =="SQL")
                                  s_sql = "select sum(isnull(stock_qty_m,0)) as stock_qty_m  from " + main.g_space + ".inv_sku_pallet  where inv_org = '"+main.g_org+"' and consignor ='" + s_consignor + "' and location_code = '" + s_outloc + "' and  pallet_no  = '" + s_pallet + "' ";
                              else
                                  s_sql = "select sum(nvl(stock_qty_m,0)) as stock_qty_m from " + main.g_space + ".inv_sku_pallet  where inv_org = '" + main.g_org + "' and consignor ='" + s_consignor + "' and location_code = '" + s_outloc + "' and pallet_no = '" + s_pallet + "'  ";
                              try
                              {
                                  if (main.dbtype == "SQL")
                                      dt_pallet = main.dbservice.Sql_exec_selectsql(s_sql);
                                  else
                                      dt_pallet = main.dbservice.oracle_exec_selectsql(s_sql);

                              }
                              catch (System.Exception ee)
                              {
                                  MessageBox.Show(main.g_class.comm_getchangestring("Fail to get pallet stock !", main.g_info_dataset) + ee.ToString());
                                  return;
                              }
                              d_pallet_qty =Math.Round( System.Convert.ToDecimal(dt_pallet.Tables[0].Rows[0][0].ToString().Trim()),4);
                              if (d_pallet_qty != d_qty && s_pallet == s_inpallet)
                                  s_inpallet = "";
                             //判断托盘是否已用
                             string str_sql, str_tray, s_skus;
                             DataSet dt_tray;
                             int d_temp;
                             s_skus = (string)dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_sku"].EditedFormattedValue.ToString().Trim();

                             str_sql = "select pallet_flag from " + main.g_space + ".mst_sku where inv_org = '" + main.g_org + "' and consignor ='" + s_consignor + "' and sku = '" + s_skus + "' ";
                             try
                             {

                                 if (main.dbtype == "SQL")
                                     dt_tray = main.dbservice.Sql_exec_selectsql(str_sql);
                                 else
                                     dt_tray = main.dbservice.oracle_exec_selectsql(str_sql);

                             }
                             catch (System.Exception ee)
                             {
                                 MessageBox.Show(main.g_class.comm_getchangestring("Fail to get pallet flag !", main.g_info_dataset) + ee.ToString());
                                 return;
                             }
                             str_tray = dt_tray.Tables[0].Rows[0][0].ToString().Trim();
                             //如果是托盘管理，先要判断扫面的托盘号是否已经在库存中存在或者在为上架的记录存在，
                             if (str_tray == "1")
                             {
                                 if (s_inpallet != "")
                                 {
                                     if (s_inpallet != "000000000000000")
                                     {
                                         if(main.dbtype =="SQL")
                                             str_sql = "select count(*) from " + main.g_space + ".inv_sku_pallet where inv_org = '" + main.g_org + "' and pallet_no = '" + s_inpallet + "' and location_code <> '" + s_outloc + "' and (stock_qty_m -isnull(freeze_qty_m,0)) > 0";
                                         else
                                             str_sql = "select count(*) from " + main.g_space + ".inv_sku_pallet where inv_org = '" + main.g_org + "' and pallet_no = '" + s_inpallet + "' and location_code <> '" + s_outloc + "' and (stock_qty_m -nvl(freeze_qty_m,0)) > 0";
                                         if (main.dbtype == "SQL")
                                             d_temp = main.dbservice.Sql_exec_selectint(str_sql);
                                         else
                                             d_temp = main.dbservice.oracle_exec_selectint(str_sql);
                                         if (d_temp > 0) //说明托盘不合法
                                         {
                                             MessageBox.Show(main.g_class.comm_getchangestring("the pallet is illegimate", main.g_info_dataset) + "!");
                                             return;
                                         }
                                         else
                                         {
                                             str_sql = "select count(*) from " + main.g_space + ".asn_putaway where inv_org = '" + main.g_org + "' and pallet_no = '" + s_inpallet + "' and putaway_status = '0'";
                                             if (main.dbtype == "SQL")
                                                 d_temp = main.dbservice.Sql_exec_selectint(str_sql);
                                             else
                                                 d_temp = main.dbservice.oracle_exec_selectint(str_sql);
                                             if (d_temp > 0)
                                             {
                                                 MessageBox.Show(main.g_class.comm_getchangestring("the pallet is illegimate", main.g_info_dataset) + "!");
                                                 return;
                                             }
                                         }
                                     }

                                 }
                             }
                    try
                    {
                        //  移库新增 
                        if (main.dbtype == "SQL")
                            main.dbservice.Sql_exec_proc_repleadd(main.g_org, s_consignor, s_move_no, i_line, s_outloc, s_inloc, s_pallet, s_inpallet, s_bat, d_qty, d_pallet_qty, main.g_user, "0");
                        else
                            main.dbservice.oracle_exec_proc_repleadd(main.g_org, s_consignor, s_move_no, i_line, s_outloc, s_inloc, s_pallet, s_inpallet, s_bat, d_qty, d_pallet_qty, main.g_user, "0");
                      
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to comfirm", main.g_info_dataset) + "!" + str_ren + ee.ToString().Trim());
                        Cursor.Current = Cursors.Default;
                        return;
                    }
                }
                else
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("The quantity can't be zero ", main.g_info_dataset) + "!");
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }
            else if (g_str_oper == 2) //说明是修改
            {
                string str_outlocation, str_batchno, str_customer, str_skus,str_inloc,str_pack;
                decimal  d_outqty;
                str_pack = dataGridView3.Rows[0].Cells["E_pack_code"].EditedFormattedValue.ToString().Trim();
                str_inloc = dataGridView3.Rows[0].Cells["E_replenishin_location"].EditedFormattedValue.ToString().Trim();
                //判断库位是否可修改
              
                //判断数量是否有为0的
                for (int i = 0; i < modify.Rows.Count; i++)
                {
                    str_outlocation = modify.Rows[i]["location_code"].ToString().Trim(); 
                    str_batchno = modify.Rows[i]["batch_no"].ToString().Trim();
                    str_customer = modify.Rows[i]["consignor"].ToString().Trim();
                    str_skus = modify.Rows[i]["sku"].ToString().Trim();
                    d_outqty = System.Convert.ToDecimal(modify.Rows[i]["old_qty"].ToString().Trim()) - System.Convert.ToDecimal(modify.Rows[i]["qty"].ToString().Trim());
                    //判断库位是否合法
                    string str_loc = "";
                    try
                    {
                        if (main.dbtype == "SQL")
                        {
                            str_loc = main.dbservice.Sql_exec_proc_moveloc(main.g_org, str_customer, str_skus, str_inloc, str_outlocation, d_outqty, str_pack);
                        }
                        else
                        {
                            str_loc = main.dbservice.oracle_exec_proc_moveloc(main.g_org, str_customer, str_skus, str_inloc, str_outlocation, d_outqty, str_pack);
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get location  Information  !", main.g_info_dataset) + ee.ToString());
                        Cursor.Current = Cursors.Default;
                        return;
                    }
                    if (str_loc == "UNKNOWN")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get location  Information  !", main.g_info_dataset));
                        return;
                    }
                    
                    if (System.Convert.ToDecimal(modify.Rows[i]["qty"].ToString().Trim()) == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("The quantity can't be zero ", main.g_info_dataset) + "!");
                        Cursor.Current = Cursors.Default;
                        return;
                    }
                }
                try
                {
                    DataSet ds_modify = new DataSet();
                    ds_modify.Tables.Add(modify);
                    if (main.dbtype == "SQL")
                        main.dbservice.Sql_exec_proc_replemodify(main.g_org, ds_modify, main.g_user);
                    else
                        main.dbservice.oracle_exec_proc_replemodify(main.g_org, ds_modify, main.g_user);
                    
                    ds_modify.Tables.Clear();
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to modify information of moving confirmation ", main.g_info_dataset) + "!" + ee.ToString().Trim());
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }
            for (int i = 0; i < dataGridView3.Columns.Count; i++)
                dataGridView3.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
            g_str_oper = 0;
            g_line_no = 0;
            dataGridView3.EditMode = DataGridViewEditMode.EditProgrammatically;
            //刷新补货信息
            btn_Query_Click(sender, new EventArgs());
            this.btn_modi.Enabled = true;
            this.btn_del.Enabled = true;
            this.btn_save.Enabled = false;
            this.btn_cancel.Enabled = false;
        }

        private void bt_Close_Click(object sender, EventArgs e)
        {
            if(cbx_h_consignor.Text!="" && tb_h_move_no.Text.Trim()!="" )
            {
                try
                {
                    if (main.dbtype == "SQL")
                        main.dbservice.Sql_exec_proc_moveclose(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                    else
                        main.dbservice.oracle_exec_proc_moveclose(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to close moving bill", main.g_info_dataset) + "!" + ee.ToString().Trim());
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }
        }     
          

        private void bt_Close_Click_1(object sender, EventArgs e)
        {
            if (cbx_h_consignor.Text != "" && tb_h_move_no.Text.Trim() != "")
            {
                try
                {
                    if (main.dbtype == "SQL")
                        main.dbservice.Sql_exec_proc_moveclose(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                  else
                        main.dbservice.oracle_exec_proc_moveclose(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to close replenishing bill", main.g_info_dataset) + "!" + ee.ToString().Trim());
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }
        }

        private void dataGridView2_DoubleClick(object sender, EventArgs e)
        {
            
            if (dataGridView2.CurrentRow.Index > -1)
            {
                if (str_type == "1")
                    return;
                if (dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["confirm_qty_m"].Value.ToString() == "")
                    dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["confirm_qty_m"].Value = 0;
                if (dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["replenish_qty_m"].Value.ToString() == "")
                    dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["replenish_qty_m"].Value = 0;
                if ((Convert.ToDecimal(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["replenish_qty_m"].Value) - Convert.ToDecimal(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["confirm_qty_m"].Value)) > 0 )
                {
                    if (dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["confirm_qty_m"].Value.ToString().Trim() =="")
                        L_qty = Math.Round(Convert.ToDecimal(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["replenish_qty_m"].Value.ToString().Trim()),4);
                    else
                         L_qty = Math.Round((Convert.ToDecimal(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["replenish_qty_m"].Value) - Convert.ToDecimal(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["confirm_qty_m"].Value)),4);

                    DataRow[] tr1 = dsmove_mv.Tables[0].Select("move_line_no=" + dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["move_line_no_1"].Value);
                    g_line_no = System.Convert.ToInt32(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["move_line_no_1"].Value.ToString().Trim());
                    DataRow ar = dsmove_con.Tables[0].NewRow();
                    for (int i = 0; i < dsmove_con.Tables[0].Columns.Count; i++)
                    {
                        ar[i] = tr1[0][i];
                    }
          
                    dsmove_con.Tables[0].Rows.Add(ar);
                    dataGridView2.Rows.Remove(dataGridView2.Rows[dataGridView2.CurrentRow.Index]);
                    tabControl1.SelectedIndex = 1;
                    g_str_oper = 1;
                    dataGridView3.DataSource = dsmove_con.Tables[0];
                    this.btn_modi.Enabled = false;
                    this.btn_del.Enabled = false;
                    this.btn_save.Enabled = true;
                    this.btn_cancel.Enabled = true;

                }

            }
        }

        private void dataGridView2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int i_temp;
            string str_name;
            if (e.RowIndex != -1)
            {
                i_temp = dataGridView2.CurrentRow.Index;
                str_name = dataGridView2.Columns[dataGridView2.CurrentCell.ColumnIndex].Name.ToString().Trim();
                if (str_name == "tmp_qty_m")
                {
                    if (dataGridView2.Rows[e.RowIndex].Cells["confirm_qty_s"].Value.ToString() == "")
                        dataGridView2.Rows[e.RowIndex].Cells["confirm_qty_s"].Value = 0;
                    if (dataGridView2.Rows[e.RowIndex].Cells["tmp_qty_m"].Value.ToString() == "")
                        dataGridView2.Rows[e.RowIndex].Cells["tmp_qty_m"].Value = 0;
                    if (dataGridView2.Rows[e.RowIndex].Cells["replenish_qty_m"].Value.ToString() == "")
                        dataGridView2.Rows[e.RowIndex].Cells["replenish_qty_m"].Value = 0;
                    if (Convert.ToDecimal(dataGridView2.Rows[e.RowIndex].Cells["tmp_qty_m"].Value) < 0 || Convert.ToDecimal(dataGridView2.Rows[e.RowIndex].Cells["tmp_qty_m"].Value) > (Convert.ToDecimal(dataGridView2.Rows[e.RowIndex].Cells["replenish_qty_m"].Value) - Convert.ToDecimal(dataGridView2.Rows[e.RowIndex].Cells["confirm_qty_s"].Value)))
                    {
                        dataGridView2.Rows[e.RowIndex].Cells["tmp_qty_m"].Value = 0;
                    }
                    this.bt_Confirm.Enabled = true;
                    this.bt_Cancel.Enabled = true;
                    this.bt_Close.Enabled = false;
                    g_str_oper = 1;
                }
            }
        }

        private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string str_name;
            if (e.RowIndex != -1)  //说明有选中的行有效
            {
                str_name = dataGridView2.Columns[dataGridView2.CurrentCell.ColumnIndex].Name.ToString().Trim();

                if (str_name == "tmp_qty_m") //说明是新增行，编辑
                {
                    dataGridView2.EditMode = DataGridViewEditMode.EditOnKeystroke;
                }
                else //不是新增行不能编辑
                {
                    dataGridView2.EditMode = DataGridViewEditMode.EditProgrammatically;
                }
            }
        }

        private void btn_modi_Click_1(object sender, EventArgs e)
        {
            string str_so, sp_csgo, sp_move_no;
            string str_temp ="";
            int d_so_lineno=0, d_sostatus ;
            sp_csgo = cbx_h_consignor.Text.Trim();
            sp_move_no = tb_h_move_no.Text.Trim();
            DataSet dt_so = new DataSet();
            //取出货单号
            str_temp = "select so_no,so_line_no from  " + main.g_space + ".inv_move_detail where inv_org = '" + main.g_org + "' and consignor ='" + sp_csgo + "'" +
                      "and  move_no ='" + sp_move_no + "' and batchno ='0' and moveout_pallet='0'";
            try
            {
                if (main.dbtype == "SQL")
                    dt_so = main.dbservice.Sql_exec_selectsql(str_temp);
                else
                    dt_so = main.dbservice.oracle_exec_selectsql(str_temp);
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to modfiy", main.g_info_dataset) + "!" + ee.ToString().Trim());
                return;
            }
            if (dt_so.Tables[0].Rows.Count > 0)
            {
                str_so = dt_so.Tables[0].Rows[0][0].ToString().Trim();
                if (dt_so.Tables[0].Rows[0][1].ToString().Trim() == "")
                    d_so_lineno = 0;
                else
                    d_so_lineno = System.Convert.ToInt32(dt_so.Tables[0].Rows[0][1].ToString().Trim());

                //判断出货单号是否已确认
                str_temp = "select distinct so_status  from " + main.g_space + ".so_ship_detail where inv_org = '" + main.g_org + "' and consignor ='" + sp_csgo + "'and " +
                           " so_no ='" + str_so + "' and  so_line_no = " + d_so_lineno + " ";
                try
                {
                    if (main.dbtype == "SQL")
                        dt_so = main.dbservice.Sql_exec_selectsql(str_temp);
                    else
                        dt_so = main.dbservice.oracle_exec_selectsql(str_temp);
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to modfiy", main.g_info_dataset) + "!" + ee.ToString().Trim());
                    return;
                }
                Cursor.Current = Cursors.Default;
                if (dt_so.Tables[0].Rows.Count > 0)
                {
                    d_sostatus =System.Convert.ToInt32(dt_so.Tables[0].Rows[0][0].ToString().Trim());
                    if (d_sostatus >= 3)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Can't modfiy data of relpenishment because it has been picked", main.g_info_dataset) + "!");
                        return;
                    }
                }

            }
           
            dt_save.Rows.Clear();
            tabControl1.SelectedIndex = 1;
            this.btn_modi.Enabled = false;
            this.btn_del.Enabled = false;
            this.btn_save.Enabled = true;
            this.btn_cancel.Enabled = true;
           
            g_str_oper = 2;
        }

        private void dataGridView3_CellClick(object sender, DataGridViewCellEventArgs e)
        {
          
            if (g_str_oper == 1)
            {
                string str_name;
                if (e.RowIndex != -1)  //说明有选中的行有效
                {
                    if (System.Convert.ToInt32(dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_replenish_line_no"].Value.ToString().Trim()) == g_line_no)
                    {
                        str_name = dataGridView3.Columns[dataGridView3.CurrentCell.ColumnIndex].Name.ToString().Trim();

                        if (str_name == "E_confirm_qty_m" || str_name == "E_replenishin_pallet") //说明是新增行，编辑
                        {
                            dataGridView3.EditMode = DataGridViewEditMode.EditOnKeystroke;
                        }
                        else //不是新增行不能编辑
                        {
                            dataGridView3.EditMode = DataGridViewEditMode.EditProgrammatically;
                        }
                    }
                    else
                        return;
                }
            }
            if (g_str_oper == 2)
            {
                string str_name;
                if (e.RowIndex != -1)  //说明有选中的行有效
                {
                    str_name = dataGridView3.Columns[dataGridView3.CurrentCell.ColumnIndex].Name.ToString().Trim();

                    if (str_name == "E_confirm_qty_m") //说明是修改，编辑
                    {
                        dataGridView3.EditMode = DataGridViewEditMode.EditOnKeystroke;
                    }
                    else //不是修改不能编辑
                    {
                        dataGridView3.EditMode = DataGridViewEditMode.EditProgrammatically;
                    }
                }
            }
        }

        private void btn_del_Click_1(object sender, EventArgs e)
        {
            string sp_csgo, sp_move_no, p_sku, sp_loc, sp_bat, sp_pallet,str_inloc,str_pack;
            decimal d_qty;
            int sp_line_no;
            int i_temp;
            string str_so;
            string str_temp = "";
            int d_so_lineno=0, d_sostatus;
            DataSet dt_so = new DataSet();

            if (dataGridView3.CurrentRow != null)  //说明选择了行号
            {
                i_temp = dataGridView3.CurrentRow.Index;
                sp_csgo = cbx_h_consignor.Text.Trim();
                sp_move_no = tb_h_move_no.Text.Trim();
                sp_line_no = System.Convert.ToInt32(dataGridView3.Rows[i_temp].Cells["E_replenish_line_no"].EditedFormattedValue.ToString().Trim());
                p_sku = (string)dataGridView3.Rows[i_temp].Cells["E_sku"].EditedFormattedValue.ToString().Trim();
                sp_loc = (string)dataGridView3.Rows[i_temp].Cells["E_replenishout_location"].EditedFormattedValue.ToString().Trim();
                sp_bat = (string)dataGridView3.Rows[i_temp].Cells["E_batchno"].EditedFormattedValue.ToString().Trim();
                sp_pallet = (string)dataGridView3.Rows[i_temp].Cells["E_replenishout_pallet"].EditedFormattedValue.ToString().Trim();
                str_inloc = (string)dataGridView3.Rows[i_temp].Cells["E_replenishin_location"].EditedFormattedValue.ToString().Trim();
                str_pack = (string)dataGridView3.Rows[i_temp].Cells["E_pack_code"].EditedFormattedValue.ToString().Trim();
                d_qty = System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim());
                
                //取出货单号
                str_temp = "select so_no,so_line_no from  " + main.g_space + ".inv_move_detail where inv_org = '" + main.g_org + "' and consignor ='" + sp_csgo + "'" +
                          "and  move_no ='" + sp_move_no + "' and batchno ='0' and moveout_pallet='0'";
                try
                {
                    if (main.dbtype == "SQL")
                        dt_so = main.dbservice.Sql_exec_selectsql(str_temp);
                    else
                        dt_so = main.dbservice.oracle_exec_selectsql(str_temp);
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to delete", main.g_info_dataset) + "!" + ee.ToString().Trim());
                    return;
                }
                if (dt_so.Tables[0].Rows.Count > 0)
                {
                    str_so = dt_so.Tables[0].Rows[0][0].ToString().Trim();
                    if (dt_so.Tables[0].Rows[0][1].ToString().Trim() == "")
                        d_so_lineno = 0;
                    else
                    d_so_lineno = System.Convert.ToInt32(dt_so.Tables[0].Rows[0][1].ToString().Trim());

                    //判断出货单号是否已确认
                str_temp = "select distinct so_status  from " + main.g_space + ".so_ship_detail where inv_org = '" + main.g_org + "' and consignor ='" + sp_csgo + "'and " +
                               " so_no ='" + str_so + "' and  so_line_no = " + d_so_lineno + " ";
                    try
                    {
                        if (main.dbtype == "SQL")
                            dt_so = main.dbservice.Sql_exec_selectsql(str_temp);
                        else
                            dt_so = main.dbservice.oracle_exec_selectsql(str_temp);
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to delete", main.g_info_dataset) + "!" + ee.ToString().Trim());
                        return;
                    }
                    Cursor.Current = Cursors.Default;
                    if (dt_so.Tables[0].Rows.Count > 0)
                    {
                        d_sostatus = System.Convert.ToInt32(dt_so.Tables[0].Rows[0][0].ToString().Trim());
                        if (d_sostatus >= 3)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Can't delete data of relpenishment because it has been picked", main.g_info_dataset) + "!");
                            return;
                        }
                    }
                }
                //判断库位是否合法
                string str_loc = "";
                try
                {
                    if (main.dbtype == "SQL")
                    {
                        str_loc = main.dbservice.Sql_exec_proc_moveloc(main.g_org, sp_csgo, p_sku, str_inloc, sp_loc, d_qty, str_pack);
                    }
                    else
                    {
                        str_loc = main.dbservice.oracle_exec_proc_moveloc(main.g_org, sp_csgo, p_sku, str_inloc, sp_loc, d_qty, str_pack);
                    }

                }

                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to get location  Information ", main.g_info_dataset) + ee.ToString());
                    Cursor.Current = Cursors.Default;
                    return;
                }
                if (str_loc == "UNKNOWN")
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to get location  Information ", main.g_info_dataset));
                    return;
                }

            }
            else
                return;
            if (MessageBox.Show(main.g_class.comm_getchangestring("Are you sure to delete , information", main.g_info_dataset) + "?", main.g_class.comm_getchangestring("Information", main.g_info_dataset), MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                Cursor.Current = Cursors.WaitCursor;
                try
                {
                    if (main.dbtype == "SQL")

                        main.dbservice.Sql_exec_proc_repledelete(main.g_org, sp_csgo, sp_move_no, sp_line_no, p_sku, sp_loc, sp_bat, sp_pallet, main.g_user);
                    else
                        main.dbservice.oracle_exec_proc_repledelete(main.g_org, sp_csgo, sp_move_no, sp_line_no, p_sku, sp_loc, sp_bat, sp_pallet, main.g_user);
                    
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to delete", main.g_info_dataset) + "!" + ee.ToString().Trim());
                }
                Cursor.Current = Cursors.Default;
            }
            btn_Query_Click(sender, new EventArgs());
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            g_str_oper = 0;
            dataGridView3.EditMode = DataGridViewEditMode.EditProgrammatically;
            //刷新补货信息
            btn_Query_Click(sender, new EventArgs());
            this.btn_modi.Enabled = true;
            this.btn_del.Enabled = true;
            this.btn_save.Enabled = false;
            this.btn_cancel.Enabled = false;

        }


        private void w_so014_Load(object sender, EventArgs e)
        {
            //获取分配是到库位还是到批次
            try
            {

                if (main.dbtype == "SQL")
                {
                    string str_sql2 = "select ltrim(rtrim(isnull(max(id_data),'0')))  from " + main.g_space + ".Sys_Parameter where inv_org = '" + main.g_org + "' and id = 8201";
                    str_type = main.dbservice.Sql_exec_selectstring(str_sql2).Trim();
                }
                else
                {
                    string str_sql2 = "select trim(nvl(max(id_data),'0'))  from " + main.g_space + ".Sys_Parameter where inv_org = '" + main.g_org + "' and id = 8201";
                    str_type = main.dbservice.oracle_exec_selectstring(str_sql2).Trim();
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(ee.ToString());
            }
            int i_cbx = 0;
            ArrayList al_cbx = new ArrayList();
            modify = new DataTable();
            modify.Columns.Add("old_qty");
            modify.Columns.Add("qty");
            modify.Columns.Add("inv_org");
            modify.Columns.Add("consignor");
            modify.Columns.Add("move_no");
            modify.Columns.Add("move_line_no");
            modify.Columns.Add("sku");
            modify.Columns.Add("location_code");
            modify.Columns.Add("batch_no");
            modify.Columns.Add("pallet_no");
            modify.Columns.Add("in_pallet_no");
            dt_save = new DataTable();
            dt_save.Columns.Add("inv_org");
            dt_save.Columns.Add("consignor");
            dt_save.Columns.Add("so_no");
            dt_save.Columns.Add("so_line_no");
            dt_save.Columns.Add("sku");
            dt_save.Columns.Add("location_code");
            dt_save.Columns.Add("qty");
            dt_save.Columns.Add("n_ea_cubage");
            dt_save.Columns.Add("n_ea_gross");
            dt_save.Columns.Add("n_ea_net");
            //当新增的时候old_qty 如果库存可用数量大于缺货数量则是缺货数量 ，否则是库存可用数量 ，修改就是原计划数量
            dt_save.Columns.Add("old_qty");
            //当新增的时候old_qty 如果库存可用数量大于缺货数量则是缺货数量 ，否则是库存可用数量 ，修改就是原计划数量
            try
            {
                dscustomer = new DataSet();
                dscustomer = main.g_class.comm_get_consignor();
                cb_consignor.DataSource = dscustomer.Tables[0];
                cb_consignor.ValueMember = "consignor";
                cb_consignor.DisplayMember = "consignor";

                i_cbx = cb_q_status.Items.Count;
                al_cbx.Clear();
                if (i_cbx > 0)
                {
                    for (int i = 0; i < i_cbx; i++)
                    {
                        if (cb_q_status.Items[i].ToString().Trim() != "")
                            al_cbx.Add(main.g_class.comm_getchangestring(cb_q_status.Items[i].ToString().Trim(), main.g_info_dataset));
                    }
                    //清除cbx_bookstatus
                    cb_q_status.Items.Clear();
                    //在加入
                    i_cbx = al_cbx.Count;
                    for (int i = 0; i < i_cbx; i++)
                    {
                        cb_q_status.Items.Add(al_cbx[i]);
                    }
                    //出来在加上空值
                    //cbx_bookstatus.Items.Add("");
                    cb_q_status.Items.Add("");
                }

                i_cbx = cb_move_type.Items.Count;
                al_cbx.Clear();
                if (i_cbx > 0)
                {
                    for (int i = 0; i < i_cbx; i++)
                    {
                        if (cb_move_type.Items[i].ToString().Trim() != "")
                            al_cbx.Add(main.g_class.comm_getchangestring(cb_move_type.Items[i].ToString().Trim(), main.g_info_dataset));
                    } 
                    //清除cbx_bookstatus
                    cb_move_type.Items.Clear();
                    //在加入
                    i_cbx = al_cbx.Count;
                    for (int i = 0; i < i_cbx; i++)
                    {
                        cb_move_type.Items.Add(al_cbx[i]);
                    }
                    //出来在加上空值
                    //cbx_bookstatus.Items.Add("");
                    cb_move_type.Items.Add("");
                }

                //i_cbx = cb_h_move_status.Items.Count;
                //al_cbx.Clear();
                //if (i_cbx > 0)
                //{
                //    for (int i = 0; i < i_cbx; i++)
                //    {
                //        if (cb_h_move_status.Items[i].ToString().Trim() != "")
                //            al_cbx.Add(main.g_class.comm_getchangestring(cb_h_move_status.Items[i].ToString().Trim(), main.g_info_dataset));
                //    }
                //    //清除cbx_bookstatus
                //    cb_h_move_status.Items.Clear();
                //    //在加入
                //    i_cbx = al_cbx.Count;
                //    for (int i = 0; i < i_cbx; i++)
                //    {
                //        cb_h_move_status.Items.Add(al_cbx[i]);
                //    }
                //    //出来在加上空值
                //    //cbx_bookstatus.Items.Add("");
                //}
                main.g_class.comm_changeControl(this, main.g_win_dataset);

                //转换右键菜单
                if (CMS_DISPLAY.Items.Count > 0)
                {
                    for (int i = 0; i < CMS_DISPLAY.Items.Count; i++)
                    {
                        CMS_DISPLAY.Items[i].Text = main.g_class.comm_getchangestring(CMS_DISPLAY.Items[i].Text.Trim(), main.g_info_dataset);
                        if (main.g_class.comm_find_module(CMS_DISPLAY.Items[i].Tag.ToString().Trim()))
                        {
                            CMS_DISPLAY.Items[i].Enabled = true;
                        }
                        else
                        {
                            CMS_DISPLAY.Items[i].Enabled = false;
                        }
                    }
                }

                g_str_oper = 0;
                dataGridView3.EditMode = DataGridViewEditMode.EditProgrammatically;
                dataGridView2.EditMode = DataGridViewEditMode.EditProgrammatically;
                dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
                this.btn_modi.Enabled = true;
                this.btn_del.Enabled = true;
                this.btn_save.Enabled = false;
                this.btn_cancel.Enabled = false;

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Consignor's Information!", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
            //对日期控件Format
            dtp_made_time.CustomFormat = "yyyy.MM.dd";
            dtp_made_time.Format = DateTimePickerFormat.Custom;
            dtp_made_time_end.CustomFormat = "yyyy.MM.dd";
            dtp_made_time_end.Format = DateTimePickerFormat.Custom;
            dtp_made_time.Value = System.Convert.ToDateTime(DateTime.Now.ToString("yyyy.MM.dd").Trim());
            dtp_made_time_end.Value = System.Convert.ToDateTime(DateTime.Now.AddDays(7).ToString("yyyy.MM.dd").Trim());
            //获取按钮权限

            string str_right;

            str_right = main.g_class.comm_getright("w_so014", main.g_right_dataset);

            //新增
            if (str_right.Substring(0, 1) == "0")
            {
                bt_Direction.Visible = false;
            }
            else
            {
                bt_Direction.Visible = true;
            }
            //修改
            if (str_right.Substring(1, 1) == "0")
            {
                btn_modi.Visible = false;
            }
            else
            {
                btn_modi.Visible = true;
            }
            //删除
            if (str_right.Substring(2, 1) == "0")
            {
                btn_del.Visible = false;
            }
            else
            {
                btn_del.Visible = true;
            }
            //保存，取消
            if (str_right.Substring(3, 1) == "0")
            {
                btn_save.Visible = false;
                btn_cancel.Visible = false;
            }
            else
            {
                btn_save.Visible = true;
                btn_cancel.Visible = true;
            }

            //确认，取消
            if (str_right.Substring(4, 1) == "0")
            {
                bt_Confirm.Visible = false;
                bt_Cancel.Visible = false;
            }
            else
            {
                bt_Confirm.Visible = true;
                bt_Cancel.Visible = true;
            }
            //关闭
            if (str_right.Substring(5, 1) == "0")
            {
                bt_Close.Visible = false;
            }
            else
            {
                bt_Close.Visible = true;
            }

            s_enter_flag = "0";
            if (s_pop_sono != null)
            {
                if (s_pop_sono.Trim() != "")  //说明是快捷方式过来的
                {
                    dtp_made_time.Value = System.Convert.ToDateTime(DateTime.Now.AddDays(-30).ToString("yyyy.MM.dd").Trim());
                    dtp_made_time_end.Value = System.Convert.ToDateTime(DateTime.Now.AddDays(30).ToString("yyyy.MM.dd").Trim());
                    cb_consignor.Text = s_pop_consignor;
                    //tb_so.Text = s_pop_sono;
                    s_enter_flag = "1";
                }
            }
            s_pop_consignor = "";
            s_pop_sono = "";   
        }

        private void w_so014_Enter(object sender, EventArgs e)
        {
            if (s_enter_flag == "1")
            {
                btn_Query_Click(sender, new EventArgs());
            }
            else
            {
                s_enter_flag = "1";
            }
        }

        private void deliveryManagementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(deliveryManagementToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开 
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so001.s_pop_sono = "";
                    w_so001.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so001 so001 = new w_so001();
            so001.Text = deliveryManagementToolStripMenuItem.Text.Trim();
            so001.Show(main.dp_pop, DockState.Document);
        }

        private void waveManagementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(waveManagementToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开 
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so002.s_pop_sono = "";
                    w_so002.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so002 so002 = new w_so002();
            so002.Text = waveManagementToolStripMenuItem.Text.Trim();
            so002.Show(main.dp_pop, DockState.Document);
        }

        private void allocationManagementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(allocationManagementToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so003.s_pop_sono = "";
                    w_so003.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so003 so003 = new w_so003();
            so003.Text = allocationManagementToolStripMenuItem.Text.Trim();
            so003.Show(main.dp_pop, DockState.Document);
        }

        private void pickManagementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(pickManagementToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so005.s_pop_sono = "";
                    w_so005.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so005 so005 = new w_so005();
            so005.Text = pickManagementToolStripMenuItem.Text.Trim();
            so005.Show(main.dp_pop, DockState.Document);
        }

        private void wavePickConfirmationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(wavePickConfirmationToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so007.s_pop_sono = "";
                    w_so007.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so007 so007 = new w_so007();
            so007.Text = wavePickConfirmationToolStripMenuItem.Text.Trim();
            so007.Show(main.dp_pop, DockState.Document);
        }

        private void shipManagementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(shipManagementToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so006.s_pop_sono = "";
                    w_so006.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so006 so006 = new w_so006();
            so006.Text = shipManagementToolStripMenuItem.Text.Trim();
            so006.Show(main.dp_pop, DockState.Document);
        }

        private void replenishmentManagementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(replenishmentManagementToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so004.s_pop_sono = "";
                    w_so004.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so004 so004 = new w_so004();
            so004.Text = replenishmentManagementToolStripMenuItem.Text.Trim();
            so004.Show(main.dp_pop, DockState.Document);
        }

        private void sOQueryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(sOQueryToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so008.s_pop_sono = "";
                    w_so008.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so008 so008 = new w_so008();
            so008.Text = sOQueryToolStripMenuItem.Text.Trim();
            so008.Show(main.dp_pop, DockState.Document);
        }

        private void pickPrintToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(pickPrintToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so010.s_pop_sono = "";
                    w_so010.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so010 so010 = new w_so010();
            so010.Text = pickPrintToolStripMenuItem.Text.Trim();
            so010.Show(main.dp_pop, DockState.Document);
        }

        private void wavePickPrintToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(wavePickPrintToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so009.s_pop_sono = "";
                    w_so009.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so009 so009 = new w_so009();
            so009.Text = wavePickPrintToolStripMenuItem.Text.Trim();
            so009.Show(main.dp_pop, DockState.Document);
        }

        private void replenishmentPrintToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(replenishmentPrintToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so011.s_pop_sono = "";
                    w_so011.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so011 so011 = new w_so011();
            so011.Text = replenishmentPrintToolStripMenuItem.Text.Trim();
            so011.Show(main.dp_pop, DockState.Document);
        }

        private void soPrintToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(soPrintToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so016.s_pop_sono = "";
                    w_so016.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so016 so016 = new w_so016();
            so016.Text = soPrintToolStripMenuItem.Text.Trim();
            so016.Show(main.dp_pop, DockState.Document);
        }

        private void shipPrintToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //首先要找到
            IDockContent curidc;
            curidc = main.g_class.Findwindows(shipPrintToolStripMenuItem.Text.Trim());
            if (curidc != null) //说明已经打开
            {
                curidc.DockHandler.Close();
            }
            //然后重新打开
            if (dataGridView1.CurrentRow != null)
            {
                if (dataGridView1.CurrentRow.Index >= 0)
                {
                    w_so015.s_pop_sono = "";
                    w_so015.s_pop_consignor = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].EditedFormattedValue.ToString().Trim();
                }
            }
            w_so015 so015 = new w_so015();
            so015.Text = shipPrintToolStripMenuItem.Text.Trim();
            so015.Show(main.dp_pop, DockState.Document);
        }
    }  
}